<template>
	<AbnormalTemplate :treeData="treeData" @treeHandle="treeHandle" :datePickType="datePickType">
		<div slot="leftRule" style="font-size:14px;">
			&emsp;&emsp;状态：
			<el-select clearable v-model="listQuery.status" placeholder="请选择">
				<el-option
					v-for="item in statusList"
					:key="item.value"
					:label="item.label"
					:value="item.value"
				>
				</el-option>
			</el-select>
		</div>
		<div slot="rightBtn">&nbsp;<el-button @click="downloadExcel">导出</el-button></div>
		<Table
			:tableData="tableData"
			:tableHead="tableHead"
			:propKey="{ prop: 'id', label: 'name' }"
			:isUseSlot="false"
			:page="listQuery.page"
			:limit="listQuery.limit"
			v-loading="listLoading"
			@handleEdit="handleEdit"
		>
		</Table>
		<Pagination
			v-show="total > 0"
			:total="total"
			:page.sync="listQuery.page"
			:limit.sync="listQuery.limit"
			@pagination="getList"
		></Pagination>
	</AbnormalTemplate>
</template>
<script>
import AbnormalTemplate from "@/template/abnormal.temp.vue";
import Table from "@/components/Table";
import Pagination from "@/components/Pagination"; // 分页
import { getHistoryList } from "@/api/RCIM/RCIM-nuclearSafetyRanking";
import {
	exportExcelHistoryData
} from "@/api/RCIM/RCIM-downloadFile";
import moment from "moment";
export default {
	name: "KdHistoryData",
	components: { AbnormalTemplate, Table, Pagination },
	data() {
		return {
			treeData: {},
			total: 5,
			listLoading: true,
			datePickType: {
				precise: "datetimerange",
				format: "yyyy-MM-dd HH:mm",
			},
			statusList: window.SYSTEM_CHECK_CONFIG.historyData,
			listQuery: {
				page: 1,
				limit: 10,
				nodeId: undefined,
				startTime: undefined,
				endTime: undefined,
				status: ""
			},
			tableData: [],
			tableHead: [
				{
					id: "enterprise",
					name: "企业",
					width: ""
				},
				{
					id: "sourceCode",
					name: "源国家编码",
					width: "",
					align: "center"
				},
				{
					id: "nucleusName",
					name: "核素名称",
					width: "",
					align: "center"
				},
				{
					id: "applicationType",
					name: "应用类型",
					width: "",
					align: "center"
				},
				{
					id: "dose",
					name: "剂量",
					width: "",
					align: "center"
				},
				{
					id: "status",
					name: "状态",
					align: "center",
					width: ""
				},
				{
					id: "sourceType",
					name: "源类别",
					align: "center",
					width: ""
				},
				{
					id: "colletTime",
					name: "采集时间",
					align: "center",
					width: ""
				}
			]
		};
	},
	mounted() {

	},
	mounted() {
	},
	methods: {
		/**
		 * @desc 导出excel
		 */
		downloadExcel(){
			this.$confirm('确认要导出为Excel吗？')
				.then(_ => {
					this.donloadLoading = true;
					this.getExcel({
						callback: exportExcelHistoryData,
						params: this.listQuery,
						id: 'KdHistoryData'
					}).then(res => {
						this.donloadLoading = false;
					}).catch(err => {
						this.donloadLoading = false;
					})
				})
				.catch(_ => {});
		},
		handleEdit(row) {
			console.log(row);
		},
		/**
		 * @desc 点击左侧树回调
		 * @param {Object} param 树节点参数
		 */
		treeHandle(param) {
			console.log(param);
			this.listQuery.nodeId = param.id;
			this.listQuery.nodeType = param.type;
			this.listQuery.startTime = moment(param.startTime).format('YYYY-MM-DD HH:mm');
			this.listQuery.endTime = moment(param.endTime).format('YYYY-MM-DD HH:mm');
			this.listQuery.treeType = param.treeType;
			this.getList();

		},
		/**
		 * @desc 获取表格数据
		 */
		async getList() {
			this.listLoading = true;
			const { data } = await getHistoryList(this.listQuery);
			this.total = data.total;
			this.tableData = data.historyList;
			this.listLoading = false;
		}
	}
};
</script>

<style lang="scss" scoped></style>
